import cv2
import numpy as np
import os

lower_blue = np.array((20, 22, 20))

upper_blue = np.array((255,255, 255))
# 确定目标物体的HSV范围 此范围为蓝色


frame = cv2.imread('/home/ubuntu/code/ssd.pytorch/data/pollen_data_multi_classes/test/JPEGImages/shjingshan8.30165_3.jpg')
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower_blue, upper_blue)
res = cv2.bitwise_and(frame, frame, mask=mask)
cv2.imshow('frame', frame)
cv2.imshow('mask', mask)
cv2.imshow('res', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
# r = '/home/ubuntu/code/ssd.pytorch/data/pollen_data_multi_classes/train/JPEGImages/'
# l = len(os.listdir(r))
# s = np.zeros((512,512,3))
#
# c = 0
#
# for i in os.listdir(r):
#     im = cv2.imread(r + i).astype(np.float32)
#     h,w,_ = im.shape
#     if h!=512 or w!= 512:
#         continue
#     c+=1
#     s+=im
#
# s = s/c
# s = s.mean(axis=0)
# s = s.mean(axis=0)
# print(s)

#     im *= 0.5
#     im[im > 255] = 255
#     im = im.astype('uint8')
#     cv2.imwrite('./color/' + i, im)
